package cn.hui.utils;


import org.springframework.util.StringUtils;

public class BeanUtils {
	
	public static String getFieldName(String fieldName){
		int index = 0;
		while((index = fieldName.indexOf("_"))!=-1){
			if(index==fieldName.length()-1) return fieldName.substring(0, 1).toLowerCase()+fieldName.substring(1,index);
			fieldName = fieldName.substring(0, index)+fieldName.substring(index+1, index+2).toUpperCase()+fieldName.substring(index+2);
		}
		
		return fieldName.substring(0, 1).toLowerCase()+fieldName.substring(1);
	}
	
	
	 public static String getBeanName(String tableName,int preOrSu,String separator) {
	        String tn = tableName.toLowerCase();
	        switch (preOrSu) {
	        case -1:
	            tn = tn.substring(tn.indexOf(separator));
	            break;
	        case 1:
	            tn = tn.substring(0, tn.length() - tn.lastIndexOf(separator));
	            break;
	        case 2:
	            String tempTn = tn.substring(tn.indexOf(separator) + 1);
	            tn = tempTn.substring(0, tempTn.lastIndexOf(separator) + 1);
	            break;
	        }
	        String[] tn_split = tn.split(separator);
	        StringBuffer sbClassName = new StringBuffer();
	        for (String tn_sub : tn_split) {
	            if(!StringUtils.isEmpty(tn_sub)){
	                sbClassName.append(tn_sub.substring(0, 1).toUpperCase()).append(
	                        tn_sub.substring(1));
	            }
	            
	        }
	        return sbClassName.toString();
	    }

}
